package com.hope.onlinestudy.fragment.examine

import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.view.View
import com.hope.onlinestudy.R
import com.hope.onlinestudy.adapter.TabVpAdapter
import com.hope.onlinestudy.fragment.examdone.ExamDoneFragment
import com.hope.onlinestudy.fragment.examstarting.ExamStartingFragment
import com.hope.onlinestudy.mvp.MVPBaseFragment
import kotlinx.android.synthetic.main.layout_tab_vfp.*
import kotlinx.android.synthetic.main.view_title.*

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */
class ExamineFragment :
    MVPBaseFragment<ExamineContract.View, ExaminePresenter>(), TabLayout.OnTabSelectedListener ,
    ExamineContract.View {

    private val examAdapter: TabVpAdapter by lazy { TabVpAdapter(childFragmentManager) }
    private val tabInndicat: Array<String> by lazy { resources.getStringArray(R.array.examarray) }
    private val itemFragments: ArrayList<Fragment> by lazy { ArrayList<Fragment>() }

    override fun initView(): Int {
        return R.layout.layout_tab_vfp
    }

    override fun bindData() {
        tv_title.text = "我的考试"
        iv_backup.visibility = View.GONE
        itemFragments.add(this)
        itemFragments.add(ExamStartingFragment())
        itemFragments.add(ExamDoneFragment())

        examAdapter.fmTitle = tabInndicat
        examAdapter.fmList = itemFragments
        vpfPage.adapter = examAdapter

        tabPolling.addOnTabSelectedListener(this)
        for (item in tabInndicat) {
            tabPolling.addTab(tabPolling.newTab().setText(item))
        }
        tabPolling.tabMode = TabLayout.MODE_FIXED
        tabPolling.setupWithViewPager(vpfPage)
    }

    override fun lazyLoad() {
    }

    override fun onTabReselected(p0: TabLayout.Tab?) {
    }

    override fun onTabUnselected(p0: TabLayout.Tab?) {
    }

    override fun onTabSelected(p0: TabLayout.Tab?) {
    }
}